import express from 'express'
import * as bodyParser from 'body-parser'
import * as swagger from 'swagger-express-ts'
import swaggerConfig from '@/config/swagger.ts'

export function setUpSwaggerUi (app: express.Application) {
  app.use('/swagger-ui/doc.html', express.static('swagger/doc.html'))
  app.use('/swagger-ui/webjars', express.static('swagger/webjars'))
  app.use('/swagger-ui/img', express.static('swagger/img'))
  app.use('/swagger-ui/oauth', express.static('swagger/oauth'))

  app.get('/swagger-ui/services.json', (req, res, next) => {
    res.json(swaggerConfig.groups)
  })
  app.use(swagger.express({
    path: '/swagger-ui/api-docs',
    definition: {
      ...swaggerConfig
    }
  }))
}
